#ifndef G3_TYPES_H
#define G3_TYPES_H

#include <climits>
#include <cstdlib>

#define G3_PI						3.1415926535897932384626433832795
#define G3_EPSILON					0.000094697

#define G3_MAX_USHORT				65535
#define G3_MAX_DOUBLE               (1 / G3_EPSILON)

#define G3_MIN(a, b)				((a) < (b) ? (a) : (b))
#define G3_MAX(a, b)				((a) < (b) ? (b) : (a))
#define G3_ABS(a)					((a) < 0 ? (-(a)) : (a))
#define G3_GETSIGN(a)				((a) < 0 ? -1 : 1)

#define G3_ROUND_UP_PRECISION		0.49
#define G3_ROUND(d)					((d - ((double) ((long) d)) > G3_ROUND_UP_PRECISION) ? ((double) ((long) d)) + 1.0 : d)

#define G3_DEG2RAD(A) ((A * M_PI) / 180.0)
#define G3_RAD2DEG(A) ((A / M_PI) * 180.0)

#define G3_SETFLAG(a, b)			(a |= b)
#define G3_TESTFLAG(a, b)           ((a & b) != 0)
#define G3_UNSETFLAG(a, b)			(a &= (~b))

typedef unsigned short word; //2
typedef unsigned char byte; //1
typedef unsigned int uint; //4
typedef uint dword; //4
typedef unsigned char uchar; //1
typedef unsigned long ulong; //4
typedef unsigned short ushort; //2

namespace G3 {

template <typename RType>
RType GetRandMinMax (RType aMin = 0, RType aMax = 1) {
    RType RandNum = (RType) rand () / RAND_MAX;
    return aMin + (aMax - aMin) * RandNum;
}

}

#endif //G3_TYPES_H
